home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Include / FWDelSta.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  6.0 KB  |  201 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDelSta.h
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWDELSTA_H
  13. #define FWDELSTA_H
  14.  
  15. #ifndef   FWEXCTAS_H
  16. #include "FWExcTas.h"
  17. #endif
  18.  
  19. #ifndef   FWPRIDEB_H
  20. #include "FWPriDeb.h"
  21. #endif
  22.  
  23. #ifndef   FWEXCRUN_H
  24. #include "FWExcRun.h"
  25. #endif
  26.  
  27. #ifndef   FWCLAINF_H
  28. #include "FWClaInf.h"
  29. #endif
  30.  
  31. class _FW_CDeleteStack;
  32. class _FW_CDeleteEntry;
  33. class _FW_CAutoDestructObject;
  34.  
  35. //========================================================================================
  36. // CLASS _FW_CDeleteEntry
  37. //========================================================================================
  38.  
  39. class _FW_CDeleteEntry
  40. {
  41. public:
  42.  
  43.     enum __DeleteType
  44.     {
  45.         __kObject,
  46.         __kGuard,
  47.         __kDeleted,
  48.         __kInvalid
  49.     };
  50.  
  51.     __DeleteType fType;
  52.     union 
  53.     {
  54.         _FW_CAutoDestructObject * fObject;
  55.         FW_ClassReference fGuard;
  56.     };
  57.  
  58.     void *fObjectVTable; // The objects v table at time of construction
  59.     
  60.     _FW_CDeleteEntry(_FW_CAutoDestructObject * anObject);
  61.     _FW_CDeleteEntry(FW_ClassReference  guard);
  62.  
  63.     __DeleteType GetType();
  64.     void SetType(__DeleteType type);
  65.     FW_ClassReference GetGuard();
  66.     _FW_CAutoDestructObject *GetObject();
  67. };
  68.  
  69.  
  70. //========================================================================================
  71. // CLASS _FW_CDeleteStack
  72. //
  73. //    The delete stack is maintained as an array of pointers to DeleteEntry, and three
  74. //    pointers into the array.  The three pointers are the StackBase, StackTop, and 
  75. //    StackLimit.  The StackBase points to the beginning of the array, the StackLimit points
  76. //    one past the last position in the array, and the StackTop points one past the last
  77. //    pushed item.  When the stack is empty, StackBase == StackTop.  When the stack is 
  78. //    full StackTop == StackLimit.  If an item is pushed when the stack is full, it is
  79. //    resized, which may move the array, so all three pointers need to be updated.  To do
  80. //    this, an integer offset RelativeTopOfStack is sometimes used to remember the location
  81. //    of a StackTop across code that might resize the stack.
  82. //
  83. //    Class Invariants:
  84. //        GetStackBase() != NULL
  85. //        GetStackBase() <= GetStackTop() <= GetStackLimit()
  86. //        GetStackTop() == GetStackBase() + RelativeTopOfStack()
  87. //        GetStackBase() + GetCurrentStackSize() == GetStackLimit()
  88. //========================================================================================
  89.  
  90. class _FW_CDeleteStack
  91. {
  92. public:
  93.     static void Initialize(FW_SPrivExceptionGlobals& globals);
  94.     static void Terminate();
  95.  
  96.     static inline void Push(_FW_CAutoDestructObject* anObject);
  97.     static inline void Push(FW_ClassReference  aGuard);
  98.  
  99.     static int IsClassExpectedInContext(_FW_CTryBlockContext *context, FW_ClassReference thrownType);
  100.         // Search for a guard that would prevent throwing this class to the next context.
  101.         // If we don't find such a guard then return true otherwise return false.
  102.  
  103.     static void PopOffAndDeleteObjectsInContext(FW_SPrivExceptionGlobals& globals, 
  104.                                                 _FW_CTryBlockContext *context);
  105.     static _FW_StackEntries RelativeTopOfStack(FW_SPrivExceptionGlobals& globals);
  106.     static void PopIfTopEquals(_FW_CAutoDestructObject* anObject);
  107.     static FW_ClassReference  PopGuard();
  108.  
  109. private:
  110.     static void Push(void * aGuardOrObject, _FW_CDeleteEntry::__DeleteType deleteType);
  111.  
  112.     enum
  113.     {
  114.         kNumberOfObjectsToGrowStack = 256,
  115.         kStepByteSize = kNumberOfObjectsToGrowStack * sizeof(_FW_CDeleteEntry)
  116.     };
  117.  
  118.     static void SetStackTop(FW_SPrivExceptionGlobals& globals, _FW_CDeleteEntry * pStackTop);
  119.  
  120. #ifdef FW_DEBUG
  121.     static void CheckClassInvariants(FW_SPrivExceptionGlobals& globals);
  122. #endif
  123. };
  124.  
  125. //========================================================================================
  126. // STRUCT _FW_SThrowGuard
  127. //========================================================================================
  128.  
  129. struct _FW_SThrowGuard
  130. {
  131. #ifdef FW_DEBUG
  132.     FW_ClassReference  fGuardClass;
  133. #endif
  134.     _FW_SThrowGuard();
  135.     _FW_SThrowGuard(FW_ClassReference  guard);
  136.     ~_FW_SThrowGuard();
  137. };
  138.  
  139. //========================================================================================
  140. // CLASS _FW_CDeleteEntry INLINE Functions
  141. //========================================================================================
  142.  
  143. inline _FW_CDeleteEntry::__DeleteType _FW_CDeleteEntry::GetType()
  144. {
  145.     return fType;
  146. }
  147.  
  148. inline void _FW_CDeleteEntry::SetType(__DeleteType type)
  149. {
  150.     fType = type;
  151. }
  152.  
  153. inline FW_ClassReference _FW_CDeleteEntry::GetGuard()
  154. {
  155.     FW_PRIV_ASSERT(fType == __kGuard);
  156.     return fGuard;
  157. }
  158.  
  159. inline _FW_CAutoDestructObject *_FW_CDeleteEntry::GetObject()
  160. {
  161.     FW_PRIV_ASSERT(fType == __kObject);
  162.     return fObject;
  163. }
  164.  
  165. //========================================================================================
  166. // CLASS _FW_CDeleteStack INLINE Functions
  167. //========================================================================================
  168.  
  169. inline void _FW_CDeleteStack::SetStackTop(FW_SPrivExceptionGlobals& globals, 
  170.                                           _FW_CDeleteEntry* pStackTop)
  171. {
  172. #ifdef FW_DEBUG
  173.     pStackTop->SetType(_FW_CDeleteEntry::__kInvalid);
  174. #endif
  175.     globals.gStackTop = pStackTop;
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. // _FW_CDeleteStack::RelativeTopOfStack
  180. //----------------------------------------------------------------------------------------
  181. inline _FW_StackEntries _FW_CDeleteStack::RelativeTopOfStack(FW_SPrivExceptionGlobals& globals)
  182. {
  183.     return globals.gStackTop - globals.gStackBase;
  184. }
  185.  
  186. //========================================================================================
  187. // CLASS _FW_CDeleteStack INLINE Functions (Platform independent versions)
  188. //========================================================================================
  189.  
  190. inline void _FW_CDeleteStack::Push(FW_ClassReference  aGuard)
  191. {
  192.     Push((void*) aGuard, _FW_CDeleteEntry::__kGuard);
  193. }
  194.  
  195. inline void _FW_CDeleteStack::Push(_FW_CAutoDestructObject* anObject)
  196. {
  197.     Push((void*) anObject, _FW_CDeleteEntry::__kObject);
  198. }
  199.  
  200. #endif
  201.